package nix.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class KServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		// 请求Url：
		// http://localhost:8080/java-web-demo/KServlet?username=zhangsan&pwd=123
		PrintWriter pw = response.getWriter();

		pw.println("<html><head><body>");

		pw.println(request.getScheme() + "<br/>");// http
		pw.println(request.getServerName() + "<br/>");// localhost
		pw.println(request.getServerPort() + "<br/>");// 8080
		pw.println(request.getContextPath() + "<br/>");// /java-web-demo
		pw.println(request.getServletPath() + "<br/>");// /KServlet
		pw.println(request.getQueryString() + "<br/>");// username=zhangsan&pwd=123
		pw.println(request.getRequestURI() + "<br/>");// /java-web-demo/KServlet
		pw.println(request.getRequestURL() + "<br/>");// http://localhost:8080/java-web-demo/KServlet

		pw.println("<a href='/java-web-demo/JServlet'>Go to JServlet</a>");

		pw.println("</body></head></html>");

		pw.flush();
		pw.close();
	}

}
